<template>
  <div>
      <common-head title="所有联系人"/>
      <div class="wrap">
        <van-address-list
            v-model="chosenAddressId"
            :list="$store.state.contact.contacts"
            default-tag-text="默认"
            @add="onAdd"
            @edit="onEdit"
        />
      </div>
  </div>
</template>

<script>
import CommonHead from '../../components/CommonHead.vue'
export default {
    data () {
        return{
            chosenAddressId: -1
        }
    },
    created () {
        this.initChoseId()
    },
    methods: {
        onAdd () {
            this.$router.push('./contactAdd')
        },
        onEdit () {
            alert('编辑联系人')
        },
        initChoseId () {
            const contacts = this.$store.state.contact.contacts
            const defualtContact = contacts.find(contact => contact.isDefault)
            this.chosenAddressId = defualtContact.id
        }
    },
    components: {
        CommonHead
    },
}
</script>

<style lang="scss" scoped>
.wrap{
    margin-top: 46px;
    margin-bottom: 50px;
}
</style>